package cn.szh.dao;

import cn.szh.domain.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RoleDao {


    @Select("select * from role where id in(select roleId from users_role where userId=#{uid})")
    List<Role> findRoleByUserId(int uid);
    @Select("select * from role where id not in(select roleId from users_role where userId=#{uid})")
    List<Role> findOtherRoleById(int id);
    @Insert("insert into users_role values(#{uid},#{rid})")
    void addRoleToUser(@Param("uid") int uid, @Param("rid") int rid);
    @Select("select * from role")
    List<Role> findAll();
    @Select("select * from role where id=#{rid}")
    @Results({ @Result(id=true,column = "id",property = "id"),
            @Result(column = "roleName",property = "roleName"),
            @Result(column = "roleDesc",property = "roleDesc"),
            @Result(column = "id",property = "permissions",
                    javaType = List.class,many=@Many(select = "cn.szh.dao.PermissionDao.findPermissionsByRid")),
            @Result(column = "id",property = "users",
                    javaType = List.class,many = @Many(select = "cn.szh.dao.UserDao.findUsersByRid"))

    })
    Role findById(int rid);
    //新建角色信息
    @Insert("insert into role(roleName,roleDesc) values(#{roleName},#{roleDesc})")
    void addRole(@Param("roleName") String roleName,@Param("roleDesc") String roleDesc);
}
